HAL PLAY Typical use cases for migration ¶
This section provides information about the HAL PLAY Typical use cases for migration.
The HAL1 and HAL2 PLAY drivers follow the same programming model and sequences. Below is an illustration with one single use case.
HAL PLAY gate XOR using interrupt mode ¶
This use case describes how to implement an XOR gate using PLAY in interrupt mode.
Sequence diagram ¶
Code snippet ¶
|
Example of code in HAL 1 |
Example of code in HAL 2 |
|---|---|
/* Declaration of the PLAY handle */
HAL_PLAY_HandleTypeDef hplay;
/* PLAY input configuration */
HAL_PLAY_IN_ConfTypeDef input_cfg[1];
/* PLAY LUT configuration */
HAL_PLAY_LUT_ConfTypeDef lut_cfg[1];
/* PLAY output configuration */
HAL_PLAY_OUT_ConfTypeDef out_cfg[1];
HAL_PLAY_EdgeTriggerConfTypeDef edge_cfg;
uint32_t size_array = 1U;
uint32_t its_mask = HAL_PLAY_LUT0_OUT_DIRECT;
/* Initialize the PLAY peripheral */
HAL_PLAY_Init(&hplay);
/* Input configuration */
input_cfg[0].source = HAL_PLAY1_IN_IN0_MUX0;
input_cfg[0].mode = HAL_PLAY_EDGE_DETECTION_BYPASSED;
input_cfg[0].min_pulse_width = 100;
HAL_PLAY_INPUT_SetConfig(&hplay, input_cfg, size_array);
/* LUT configuration */
lut_cfg[0].lut = HAL_PLAY_LUT0;
lut_cfg[0].truth_table = 0x6666;
lut_cfg[0].clk_gate_source = HAL_PLAY_LUT_CLK_GATE_OFF;
lut_cfg[0].input_source[HAL_PLAY_LUT_INPUT0] = HAL_PLAY_LUT_INPUT_FILTER0;
lut_cfg[0].input_source[HAL_PLAY_LUT_INPUT1] = HAL_PLAY_LUT_INPUT_SWTRIG0;
lut_cfg[0].input_source[HAL_PLAY_LUT_INPUT2] = HAL_PLAY_LUT_INPUT_DEFAULT;
lut_cfg[0].input_source[HAL_PLAY_LUT_INPUT3] = HAL_PLAY_LUT_INPUT_DEFAULT;
HAL_PLAY_LUT_SetConfig(&hplay, lut_cfg, size_array);
/* Output configuration */
out_cfg[0].output_mux = HAL_PLAY_OUT0;
out_cfg[0].lut_output = HAL_PLAY_LUT0_OUT_DIRECT;
HAL_PLAY_OUTPUT_SetConfig(&hplay, out_cfg, size_array);
/* Configure edge trigger and enable IT */
HAL_PLAY_LUT_EnableIT(&hplay, its_mask);
HAL_PLAY_LUT_SetEdgeTrigger_IT(&hplay, &edge_cfg);
HAL_PLAY_Start(&hplay, &edge_cfg);
/* LUT output Rising callback */
void HAL_PLAY_LUTOutputRisingCallback(HAL_PLAY_HandleTypeDef *hplay,
uint32_t edge_trig_mask_status)
{
/* add relative applicative code to handle LUT output Rising callback */
}
/* LUT output Falling callback */
void HAL_PLAY_LUTOutputFallingCallback(HAL_PLAY_HandleTypeDef *hplay,
uint32_t edge_trig_mask_status)
{
/* add relative applicative code to handle LUT output Falling callback */
}
|
/* Declaration of the PLAY handle */
hal_play_handle_t hplay;
/* PLAY input configuration */
hal_play_in_config_t input_cfg[1];
/* PLAY LUT configuration */
hal_play_lut_config_t lut_cfg[1];
/* PLAY output configuration */
hal_play_out_config_t out_cfg[1];
hal_play_edge_trigger_config_t edge_cfg;
uint32_t array_size = 1U;
uint32_t its_mask = HAL_PLAY_LUT0_OUT_DIRECT;
/* Initialize the PLAY peripheral and associate the handle */
HAL_PLAY_Init(&hplay, HAL_PLAY1);
/* Input configuration */
input_cfg[0].source = HAL_PLAY1_IN_IN0_MUX0;
input_cfg[0].mode = HAL_PLAY_EDGE_DETECTION_BYPASSED;
input_cfg[0].min_pulse_width = 100;
HAL_PLAY_INPUT_SetConfig(&hplay, input_cfg, array_size);
/* LUT configuration */
lut_cfg[0].lut = HAL_PLAY_LUT0;
lut_cfg[0].truth_table = 0x6666;
lut_cfg[0].clk_gate_source = HAL_PLAY_LUT_CLK_GATE_OFF;
lut_cfg[0].input_source[HAL_PLAY_LUT_INPUT0] = HAL_PLAY_LUT_INPUT_FILTER0;
lut_cfg[0].input_source[HAL_PLAY_LUT_INPUT1] = HAL_PLAY_LUT_INPUT_SWTRIG0;
lut_cfg[0].input_source[HAL_PLAY_LUT_INPUT2] = HAL_PLAY_LUT_INPUT_DEFAULT;
lut_cfg[0].input_source[HAL_PLAY_LUT_INPUT3] = HAL_PLAY_LUT_INPUT_DEFAULT;
HAL_PLAY_LUT_SetConfig(&hplay, lut_cfg, array_size);
/* Output configuration */
out_cfg[0].output_mux = HAL_PLAY_OUT0;
out_cfg[0].lut_output = HAL_PLAY_LUT0_OUT_DIRECT;
HAL_PLAY_OUTPUT_SetConfig(&hplay, out_cfg, array_size);
/* Configure edge trigger and enable IT */
HAL_PLAY_LUT_EnableIT(&hplay, its_mask);
HAL_PLAY_LUT_SetEdgeTrigger_IT(&hplay, &edge_cfg);
HAL_PLAY_Start(&hplay, &edge_cfg);
/* LUT output Rising callback */
void HAL_PLAY_LUTOutputRisingCallback(hal_play_handle_t *hplay,
uint32_t edge_trig_mask_status)
{
/* add relative applicative code to handle LUT output Rising callback */
}
/* LUT output Falling callback */
void HAL_PLAY_LUTOutputFallingCallback(hal_play_handle_t *hplay,
uint32_t edge_trig_mask_status)
{
/* add relative applicative code to handle LUT output Falling callback */
}
|

